﻿package {
	import com.mixmedia.navigation.Navigation;
	import com.mixmedia.navigation.NavigationEvent;
	
	import asunit.framework.TestCase;	

	/**
	 * @author colin
	 */
	public class NavigationTest extends TestCase {
		private var _instance : Navigation;
		
		public function NavigationTest(testMethod : String = null) {
			super(testMethod);
		}
		protected override function setUp():void {
	 		_instance = Navigation.instance();
		}

		protected override function tearDown():void {
	 		_instance = null;
	 	}
	 	
	 	public function testInstantiated():void {
	 		assertTrue("Navigation instantiated", _instance is Navigation	);
	 		assertTrue("check Navigation is Singleton ", _instance===Navigation.instance());
	 	}

		private var rspNavKey:String;
		private var rspTarget:String;
		private var rspSupress:Boolean;
	 	public function testChangeSection():void {
	 		_instance.when(NavigationEvent.CHANGE, this, addListenerChangeSection);
	 		_instance.changeSection("1_1");
			assertEquals("navKey",				'1_1',		rspNavKey);
			assertEquals("targetContainer:",	null,		rspTarget);
			assertEquals("supress:",			false,		rspSupress);
	 	}

	 	private function addListenerChangeSection(e:NavigationEvent):void{
	 		_instance.removeEventListener(e.type, addListenerChangeSection);
			rspSupress = e.isSuppress;
			rspNavKey = e.navKey;
			rspTarget = e.targetContainer;
		}
		
		public function testGetCurrentNavKey():void{
			_instance.changeSection("1_2");
			tearDown();
			assertEquals("getCurrentNavKey()",	'1_2',		Navigation.instance().getCurrentNavKey());
		}
	}
}
